@extends('layout.adminlayout')
@section('css')
    <script src="/admin/js/jquery-1.11.1.min.js"></script>
    <script src="/admin/js/metisMenu.min.js"></script>
    <script src="/admin/js/custom.js"></script>
    <link href="/admin/css/custom.css" rel="stylesheet">
    <link href="/admin/css/add_manage.css" rel="stylesheet">
@endsection
@section('content')
    <div class="forms">
        <div class=" form-grids row form-grids-right">
            <div class="widget-shadow " data-example-id="basic-forms">
                <div class="form-title">
                    <h4>添加员工账号 :</h4>
                </div>
                <div class="form-body">
                    <form action="/admin/staff/create" method="post" class="form-horizontal" id="form">
                        {{csrf_field()}}
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">
                                员工账号 :
                            </label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="account" placeholder="请以字母开头输入4~12位字母数字下划线" id="account">
                                <div class="tishi" id="a_error">

                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">
                                密码 :
                            </label>
                            <div class="col-sm-9">
                                <input type="password" class="form-control" name="password" placeholder="请输入6~18位字母数字下划线" id="password">
                                <div class="tishi" id="p_error">

                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">
                                确认密码 :
                            </label>
                            <div class="col-sm-9">
                                <input type="password" class="form-control" name="password1" placeholder="确认密码" id="password1">
                                <div class="tishi" id="p_error1">

                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">
                                联系人 :
                            </label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="linkman" placeholder="联系人(必填)" id="linkman">
                            </div>
                            <div class="tishi" id="l_error">

                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">
                                手机号 :
                            </label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="phone" placeholder="手机号(必填)" id="phone">
                                <div class="tishi" id="t_error" style="">

                                </div>
                            </div>
                        </div>
                        <div class="col-sm-offset-2">
                            <button type="button" class="btn btn-default" id="sub" style="margin-left: 0.38rem">提交</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script>
        //账号
        $('#account').blur(function () {
            var account = $('#account').val();
            var a_preg = /^[a-zA-Z_][a-zA-Z0-9_]{3,11}$/
            if(!a_preg.test(account)){
                $('#a_error').html('请以字母开头输入4~12位字母数字下划线')
            }else{
                $.ajax(
                    {
                        type:'post',
                        url:'/admin/staff/test',
                        async:false,
                        data:{
                            "_token": $("input[name=_token]").val(),
                            'account':account,
                        },
                        dataType:'json',
                        success:function (data) {
                            if(data.status == '-1'){
                                $('#a_error').html(data.msg)
                            }else{
                                $('#a_error').html('')
                            }
                        }
                    }
                )
            }
        });
        //密码
        $('#password').blur(function(){
            var password = $('#password').val();
            var p_preg = /^[a-zA-Z0-9_]{6,18}$/
            if(!p_preg.test(password)){
                $('#p_error').html('请输入6~18位字母数字下划线')
            }else{
                $('#p_error').html('')
            }
        });

        //验证密码
        $('#password1').blur(function(){
            var password = $('#password').val();
            var password1 = $('#password1').val();
            if(password != password1 || password == ''){
                $('#p_error1').html('未输入密码或两次密码不一致')
            }else{
                $('#p_error1').html('')
            }
        });

        //联系人
        $('#linkman').blur(function(){
            var linkman = $('#linkman').val();
            if(linkman == ''){
                $('#l_error').html('联系人不能为空')
            }else{
                $('#l_error').html('')
            }
        });

        //手机号
        $('#phone').blur(function () {
            var phone = $('#phone').val();
            var t_preg = /^1(3|4|5|7|8)\d{9}$/
            if(!t_preg.test(phone)){
                $('#t_error').html('手机号格式不正确')
            }else{
                $('#t_error').html('')
            }
        })

        //提交处理
        $('#sub').click(function () {
            var account = $('#account').val();
            var password = $('#password').val();
            var password1 = $('#password1').val();
            var linkman = $('#linkman').val();
            var phone = $('#phone').val();
            var a_preg = /^[a-zA-Z0-9_][a-zA-Z0-9_]{3,11}$/
            var p_preg = /^[a-zA-Z0-9_]{6,18}$/
            var t_preg = /^1(3|4|5|7|8)\d{9}$/
            if(!a_preg.test(account)){
                $('#a_error').html('请以字母开头输入4~12位字母数字下划线')
                return false;
            }else{
                $.ajax(
                    {
                        type:'post',
                        url:'/admin/staff/test',
                        async:false,
                        data:{
                            "_token": $("input[name=_token]").val(),
                            'account':account,
                        },
                        dataType:'json',
                        success:function (data) {
                            if(data.status == '-1'){
                                $('#a_error').html(data.msg)
                                return false;
                            }else{
                                $('#a_error').html('')
                                if(!p_preg.test(password)){
                                    $('#p_error').html('请输入6~18位字母数字下划线')
                                    return false;
                                }else{
                                    $('#p_error').html('')
                                    if(password != password1 || password == ''){
                                        $('#p_error1').html('未输入密码或两次密码不一致')
                                        return false;
                                    }else{
                                        $('#p_error1').html('')
                                        if(linkman == ''){
                                            $('#l_error').html('联系人不能为空')
                                            return false;
                                        }else{
                                            $('#l_error').html('')
                                            if(!t_preg.test(phone)){
                                                $('#t_error').html('手机号格式不正确')
                                                return false;
                                            }else{
                                                $('#t_error').html('')
                                                $('#form').submit();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                )
            }
        })
    </script>
@endsection
